<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#--引入外部文件-->
    <#include "../common/header.ftl">
</head>
<body>

<div class="container" style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">待发布游记管理</h1>
                </div>
            </div>
            <#--高级查询--->
            <form class="form-inline" id="searchForm" action="/travel/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入标题">
                </div>
                <button id="btn_query" class="btn btn-default">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>标题</th>
                    <th>封面</th>
                    <th>作者</th>
                    <th>地区</th>
                    <th>状态</th>
                    <th></th>
                </tr>
                <#--使用Freemark的指令完成循环迭代-->
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index + 1}</td>
                        <td>${entity.title}</td>
                        <td><img src="${entity.coverUrl}" width="30px" /></td>
                        <td>${entity.author.nickName}</td>
                        <td>${entity.place.name}</td>
                        <td>
                                <#if entity.state==-1 >
                                    已拒绝
                                    <#elseif entity.state==0>
                                    草稿
                                    <#elseif entity.state==1>
                                     待发布
                                    <#elseif entity.state==2>
                                     已发布
                                </#if>
                        </td>
                        <td>
                            <a href="javascript:" class="btn btn-info btn-xs showBtn" data-tid="${entity.id}">
                                <span class="glyphicon glyphicon-search"></span> 查看内容
                            </a>
                          <a href="javascript:" class="btn btn-primary  btn-xs changeStateBtn" data-state="2" data-tid="${entity.id}">
                              <span class="glyphicon glyphicon-plane"></span> 发布
                          </a>
                            <a href="javascript:" class="btn btn-danger btn-xs changeStateBtn" data-state="-1" data-tid="${entity.id}">
                                <span class="glyphicon glyphicon-remove"></span> 拒绝
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>

            <#include "../common/page.ftl">
        </div>
    </div>
</div>


<#--模态框必须是body的子元素-->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        <#--模态框标题-->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">查看内容</h4>
            </div>
        <#--模态框正文-->
            <div class="modal-body">

            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        //查看文章
        $(".showBtn").click(function () {
            //获取文章内容
            var id = $(this).data("tid");

            $.get('/travel/getContentById.do',{id:id},function (data) {
                $(".modal-body").html(data.content);
                $("#inputModal").modal('show');
            })

        });
        
        //修改状态
        $(".changeStateBtn").click(function () {
            //游记id
            var id = $(this).data("tid");
            //修改成指定的状态
            var state = $(this).data("state");

            $.get('/travel/changeState.do',{id:id,state:state},function (data) {
                    if(data.success){
                        if(state == -1){
                            $.post("/systemMessages/save.do",{'content':"你的文章被拒绝了",travelId:id});
                        }else if(state == 2){
                            $.post("/systemMessages/save.do",{'content':"你的文章已发布",travelId:id});
                        }
                        window.location.reload();
                    }
            })
        })
        
    })
</script>
<style>
    #inputModal img{
        width:100%
    }

    #inputModal .modal-body{
        max-height: 600px;
        overflow-y: auto;
    }
</style>
</body>
</html>